<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"
	contentType="image/jpeg"%>
<%@ page import="java.awt.Color"%>
<%@page import="java.awt.image.BufferedImage"%>
<%@page import="java.awt.Graphics2D"%>
<%@page import="java.awt.Font"%>
<%@page import="javax.imageio.ImageIO"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<base href="<%=basePath%>">

		<title>My JSP 'Random.jsp' starting page</title>

		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

	</head>

	<body>
		<%!public Color getRandColor(int fc, int bc) {
		Random r = new Random();
		if (fc > 255) {
			fc = 255;
		}
		if (bc > 255) {
			bc = 255;
		}
		int red = fc + r.nextInt(bc - fc);
		int green = fc + r.nextInt(bc - fc);
		int blue = fc + r.nextInt(bc - fc);
		return new Color(red, green, blue);
	}%>

		<%
			response.setHeader("Pragma", "No-cache");
			response.setHeader("Cache-Control", "no-cache");
			response.setDateHeader("Expires", 0);
			out.clear();
			out = pageContext.pushBody();
			Random r = new Random();

			BufferedImage pic = new BufferedImage(60, 20,
					BufferedImage.TYPE_INT_RGB);

			Graphics2D g2d = (Graphics2D) pic.getGraphics();
			g2d.setColor(getRandColor(200, 250));
			g2d.fillRect(0, 0, 60, 20);
			g2d.setFont(new Font("Times New Roman", Font.PLAIN, 18));

			g2d.setColor(getRandColor(160, 200));
			for (int i = 0; i < 200; i++) {
				int x1 = r.nextInt(60);
				int y1 = r.nextInt(20);
				int x2 = r.nextInt(15);
				int y2 = r.nextInt(15);
				g2d.drawLine(x1, y1, x2, y2);

			}

			g2d.setColor(getRandColor(120, 240));
			for (int i = 0; i < 100; i++) {
				int x = r.nextInt(60);

				int y = r.nextInt(20);

				g2d.drawOval(x, y, 0, 0);
			}
			String RS = "";
			String rn = "";
			for (int i = 0; i < 4; i++) {
				rn = String.valueOf(r.nextInt(10));
				RS += rn;
				g2d.setColor(new Color(20 + r.nextInt(110),
						20 + r.nextInt(110), 20 + r.nextInt(110)));
				g2d.drawString(rn, 13 * i + 6, 16);
			}
			g2d.dispose();
			session.setAttribute("random", RS);
			ImageIO.write(pic, "JPEG", response.getOutputStream());
		%>
	</body>
</html>
